

//
//  CompanyPrivacySettingViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/30.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CompanyPrivacySettingViewController.h"
#import "CompanyPrivacySettingFilterViewController.h"
#import "CompanyPrivacySettingModel.h"

@interface CompanyPrivacySettingViewController ()<CompanyPrivacySettingFilterViewControllerDelegate>
{
    PSCell *lookCell;
    PSCell *pushCell;
    PSCell *videoCell;
    PSCell *nicknameCell;
}
@property (nonatomic, strong) CompanyPrivacySettingModel *infoModel;
@end

@implementation CompanyPrivacySettingViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"隐私设置";
    [self loadData];
}
- (void)loadData {
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    
    [BaseNetManager requestWithMethod:POST path:CompanyMine_GetPrivacyInfo_URL params:dic successBlock:^(NSDictionary * _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            id data = responseObject[@"data"];
            self.infoModel = [[CompanyPrivacySettingModel alloc] init];
            [self.infoModel setValuesForKeysWithDictionary:data];
        }
        [self initUI];
        SVPHUDDismiss;
    } failurBlock:^(NSError * _Nonnull error) {
        SVPHUDError(NetErrorAlertText);
    }];
}

- (void)initUI {
    __weak __typeof(self)weakSelf = self;
    lookCell = [[PSCell alloc] initWithFrame:CGRectMake(30*Scale, 15*Scale, WIDTH-60*Scale, PSCellHeight) title:@"谁可以查看我的招聘信息" text:((self.infoModel && self.infoModel.viewShow.length)?self.infoModel.viewShow:nil) placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    lookCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf jumpToLookVC];
    };
    [self.view addSubview:lookCell];
    
    pushCell = [[PSCell alloc] initWithFrame:CGRectMake(30*Scale, EndY(lookCell), WIDTH-60*Scale, PSCellHeight) title:@"招聘信息推送给哪些人" text:((self.infoModel && self.infoModel.pushShow.length)?self.infoModel.pushShow:nil) placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    pushCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf jumpToPushVC];
    };
    [self.view addSubview:pushCell];
    
    videoCell = [[PSCell alloc] initWithFrame:CGRectMake(30*Scale, EndY(pushCell), WIDTH-60*Scale, PSCellHeight) title:@"谁可以在线发起视频沟通" text:((self.infoModel && self.infoModel.videoShow.length)?self.infoModel.videoShow:nil) placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    videoCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf jumpToVideoVC];
    };
    [self.view addSubview:videoCell];
    
    NSString *name = [self.infoModel.display_name isEqualToString:@"3"] ?
    @"姓氏+性别": @"我的昵称";
    
    nicknameCell = [[PSCell alloc] initWithFrame:CGRectMake(30*Scale, EndY(videoCell), WIDTH-60*Scale, PSCellHeight) title:@"访问主页是显示的身份" text:name placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    nicknameCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf jumpToNickNameVC];
    };
    [self.view addSubview:nicknameCell];
}
- (void)okBtnTap {
    
}
- (void)companyPrivacySettingFilterViewControllerType:(CompanyPrivacySettingFilterType)type info:(NSString *)info selectType:(NSString *)typestring selectArray:(NSArray *)array{
    switch (type) {
        case CompanyPrivacySettingFilterTypeOfLook: {
            lookCell.textField.text = info;
            self.infoModel.view = typestring;
            self.infoModel.view_list = [NSMutableArray arrayWithArray:array];
        } break;
        case CompanyPrivacySettingFilterTypeOfPush: {
            pushCell.textField.text = info;
            self.infoModel.push = typestring;
            self.infoModel.push_list = [NSMutableArray arrayWithArray:array];

        } break;
        case CompanyPrivacySettingFilterTypeOfVideo: {
            videoCell.textField.text = info;
            self.infoModel.video = typestring;
            self.infoModel.view_list = [NSMutableArray arrayWithArray:array];

        } break;
        case CompanyPrivacySettingFilterTypeOfName: {
            nicknameCell.textField.text = info;
            self.infoModel.display_name = typestring;
        } break;
        default:
            break;
    }
}


#pragma mark-- Action
- (void)jumpToLookVC{
    CompanyPrivacySettingFilterViewController *CPSFVC = [[CompanyPrivacySettingFilterViewController alloc] init];
    if (self.infoModel && self.infoModel.view_list.count) {
        CPSFVC.itemDataArray = self.infoModel.view_list;
    }
    CPSFVC.selectType = self.infoModel.view;
    CPSFVC.delegate = self;
    CPSFVC.type = CompanyPrivacySettingFilterTypeOfLook;
    [self.navigationController pushViewController:CPSFVC animated:YES];
}

- (void)jumpToPushVC{
    CompanyPrivacySettingFilterViewController *CPSFVC = [[CompanyPrivacySettingFilterViewController alloc] init];
    if (self.infoModel && self.infoModel.push_list.count) {
        CPSFVC.itemDataArray = self.infoModel.push_list;
        CPSFVC.pushBanDataArray = self.infoModel.push_bank_list;
    }
    CPSFVC.selectType = self.infoModel.push;
    CPSFVC.delegate = self;
    CPSFVC.type = CompanyPrivacySettingFilterTypeOfPush;
    [self.navigationController pushViewController:CPSFVC animated:YES];
}

- (void)jumpToVideoVC{
    CompanyPrivacySettingFilterViewController *CPSFVC = [[CompanyPrivacySettingFilterViewController alloc] init];
    if (self.infoModel && self.infoModel.video_list.count) {
        CPSFVC.itemDataArray = self.infoModel.video_list;
    }
    CPSFVC.selectType = self.infoModel.video;
    CPSFVC.delegate = self;
    CPSFVC.type = CompanyPrivacySettingFilterTypeOfVideo;
    [self.navigationController pushViewController:CPSFVC animated:YES];
}

- (void)jumpToNickNameVC{
    CompanyPrivacySettingFilterViewController *CPSFVC = [[CompanyPrivacySettingFilterViewController alloc] init];
    if (self.infoModel && self.infoModel.display_name.length) {
        CPSFVC.display_name = self.infoModel.display_name;
    }
    CPSFVC.selectType = self.infoModel.display_name;
    CPSFVC.delegate = self;
    CPSFVC.type = CompanyPrivacySettingFilterTypeOfName;
    [self.navigationController pushViewController:CPSFVC animated:YES];
}

@end
